package com.mdp.workflow.bus.candidate.strategy;


import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdp.core.query.QueryTools;
import com.mdp.core.utils.CollectionUtils;
import com.mdp.workflow.bus.candidate.TaskCandidateStrategy;
import com.mdp.workflow.client.entity.WfSysUser;
import com.mdp.workflow.client.service.WfSysUserService;
import com.mdp.workflow.comm.dict.CandidateStrategy;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

import static com.mdp.core.utils.BaseUtils.map;

/**
 * 动态查询条件 {@link TaskCandidateStrategy} 实现类
 *@author 唛盟开源 9哥
 */
@Component
public class HiWhereStrategy implements TaskCandidateStrategy {
    @Autowired
    WfSysUserService wfSysUserService;

    @Override
    public com.mdp.workflow.comm.dict.CandidateStrategy getStrategy() {
        return CandidateStrategy.HI_WHERE;
    }

    @Override
    public void validateParam(String param) {
        Assert.notNull(param,"部门编号不能为空，多个以逗号分隔");
    }

    @Override
    public Set<String> calculateUsers(DelegateExecution execution, String param) {
        QueryWrapper<WfSysUser> qw= QueryTools.initQueryWrapper(WfSysUser.class,map("hiQueryParams",param));
        return CollectionUtils.convertSet(wfSysUserService.selectListMapByWhere(QueryTools.initPage(),qw,map()),o->(String) o.get("userid"));
    }

}